/**
 * 
 */
package microcredit.gui.table.impl;

import java.awt.Color;
import java.util.Date;

import javax.swing.ImageIcon;

import com.jidesoft.icons.IconsFactory;

import microcredit.gui.table.EnumBeanTableModel;
import microcredit.gui.util.FormatUtilities;
import microcredit.model.MemberGroup;
import microcredit.model.domain.Status;


enum GroupColumn {
	COLUMN_SHORT_NAME,
	COLUMN_NAME,
	COLUMN_STATUS,
	COLUMN_UPDATE_STAMP;
}
public final class GroupTableModel extends
		EnumBeanTableModel<MemberGroup, GroupColumn> {

	@Override
	protected Object getValue(MemberGroup o, GroupColumn column) {
		switch (column) {
		case COLUMN_NAME : return o.getName();
		case COLUMN_SHORT_NAME : return o.getShortName();
		case COLUMN_STATUS : return o.getStatus();
		case COLUMN_UPDATE_STAMP : return o.getUpdateStamp();
		}
		return null;
	}
	
	@Override
	protected String getName(GroupColumn column) {
		switch (column) {
		case COLUMN_NAME : return "Name";
		case COLUMN_SHORT_NAME : return "Short Name";
		case COLUMN_STATUS : return "Status";
		case COLUMN_UPDATE_STAMP : return "Last update";
		}
		return null;
	}
	
	
	@Override
	protected int getWidth(GroupColumn column) {
		switch (column) {
		case COLUMN_NAME : return 200;
		case COLUMN_SHORT_NAME : return 50;
		case COLUMN_STATUS : return 30;
		case COLUMN_UPDATE_STAMP : return 150;
		}
		return 0;
	}
	
	@Override
	protected Class<?> getValueClass(GroupColumn column) {
		if (column == GroupColumn.COLUMN_UPDATE_STAMP) {
			return Date.class;
		}
		return super.getValueClass(column);
	}
	
	@Override
	public ImageIcon getRowIcon() {
		return new ImageIcon(MemberTableModel.class.getResource("/microcredit/icons/x16/users3.png"));
	}
	
	@Override
	protected Color getForeground(MemberGroup o, GroupColumn column) {
		if (o.getStatus() == Status.I) {
			return Color.red;
		}
		return super.getForeground(o, column);
	}
	
}


